<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>{:lang('set.add_problems')}</title>
    <link href="/static/admin/css/font_2321976_xoewfg91tpo.css" rel="stylesheet">
    <link href="/static/admin/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/admin/css/style.min.css" rel="stylesheet">
    <script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/admin/js/cookie.min.js"></script>
    <style>
        body {background-color:#fff;}
        .lyear-layout-content{padding-top:0;}
        .card{border:0;}
        @media screen and (max-width: 800px) {
            .card-body {
                padding: 10px;
            }
            .w-e-toolbar .w-e-menu {
                width: 30px!important;
                height: 30px!important;
            }
        }
    </style>
</head>
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <form id="myform" class="row">
                                    <div class="form-group col-md-12">
                                        <label>{:lang('set.problem')}</label>
                                        <input type="text" class="form-control" id="ask" name="ask">
                                    </div>
                                    <div class="form-group col-md-12">
                                        <label>{:lang('set.keys')}</label>
                                        <input type="text" class="form-control" id="ukeys" name="ukeys">
                                    </div>
                                    <div class="form-group col-md-12">
                                        <label>{:lang('set.sorting')}</label>
                                        <input type="text" class="form-control" id="sort" name="sort">
                                    </div>
                                    <div class="form-group col-md-12">
                                        <label style="margin-right:15px;">{:lang('set.isshown')}</label>
                                        <label class="lyear-switch switch-success">
                                            <input type="checkbox" id="isshow" checked>
                                            <span></span>
                                        </label>
                                    </div>
                                    <div class="form-group col-md-12">
                                        <label>{:lang('set.solve_answer')}</label>
                                        <div id="problem-content"></div>
                                    </div>
                                    <div class="form-group col-md-12">
                                        <button type="button" class="btn btn-primary" id="addSetProblem">{:lang('public.save')}</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </div>
</div>
<script type="text/javascript" src="/static/admin/js/set.js"></script>
<script type="text/javascript" src="/static/admin/js/wangEditor.min.js"></script>
<script type="text/javascript" src="/static/admin/layer/layer.js"></script>
<script type="text/javascript" src="/static/admin/js/common.js"></script>
<script>
    let IM_config = {
        uploadimg: "{:apiUrl('api/Upload/img')}",
        addSetProblem: "{:adminUrl('admin/Set/set_problem',['temp'=>'add_set_problem'])}"
    }
    const editor = new window.wangEditor('#problem-content');
    editor.config.menus = [
        'head',
        'bold',
        'fontSize',
        'fontName',
        'italic',
        'underline',
        'strikeThrough',
        'indent',
        'lineHeight',
        'foreColor',
        'backColor',
        'link',
        'list',
        'justify',
        'quote',
        'emoticon',
        'image',
        'table',
        'code',
        'splitLine',
        'undo',
        'redo',
    ];
    editor.config.height = 200;
    editor.config.uploadImgServer  = IM_config.uploadimg;
    editor.config.uploadImgMaxSize = 2 * 1024 * 1024;
    editor.config.uploadImgAccept  = ['jpg', 'jpeg', 'png', 'gif', 'bmp'];
    editor.config.uploadImgMaxLength = 5;
    editor.create();
    $(function() {
        /**
         * 添加常见问题
         */
        $('#addSetProblem').click(function() {
            var ask = $.trim($('#ask').val());
            if (ask == '') {
                $('#ask').focus();
                return we_im_msg('常见问题不能为空');
            }
            var ukeys = $.trim($('#ukeys').val());
            if (ukeys == '') {
                $('#ukeys').focus();
                return we_im_msg('关键词不能为空');
            }
            var sort = $.trim($('#sort').val());
            if (sort == '' || !/\d+/.test(sort)) {
                sort = 0;
            }
            var isshow = $('#isshow:checked').val()=='on'?1:0;
            var content = $.trim($('#problem-content .w-e-text').html().replace('<p><br></p>',''));
            if (content == '') {
                $('#content').focus();
                return we_im_msg('解决回答不能为空');
            }
            var data = {
                pro_ask: ask,
                pro_ukeys: ukeys,
                pro_sort: sort,
                pro_isshow: isshow,
                pro_content: content
            };
            $.ajax({
                type: "post",
                url: IM_config.addSetProblem,
                data: data,
                dataType: "json",
                success : function(r) {
                    we_im_msg(r.data);
                }
            });
            setTimeout(function() {
                parent.location.reload();
            },2000);
        });
    });
</script>
</body>
</html>